/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.dao.BranchDAO;
import com.cashmate.hibernate.pojo.Branches;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

public class GetBranches extends ActionSupport {

    private BranchDAO bran = (BranchDAO) ServletActionContext.getServletContext().getAttribute("branchDAO");
    private List<Branches> brList;
    private String loc;

    public List<Branches> getBrList() {
        return brList;
    }

    @Action(value = "/getBranches", results = {
        @Result(location = "${loc}", name = "success"),
        @Result(location = "../error/messages.jsp", name = "error",type="redirect")
    })
    public String getBranches() {
        try {
            loc = "/loanrequest.jsp?cat=headoffice";
            brList = new ArrayList<Branches>();
            brList = bran.getAll();
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
    }

    public String getLoc() {
        return loc;
    }
}
